<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Git,Xcode,iOS," />





  <link rel="alternate" href="/atom.xml" title="Bingo's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="前言用 Xcode 做 iOS 开发的同学都知道，在项目根目录里有一个  project.xcodeproj 文件。如果多人协作，项目合并的时候这个文件非常容易有冲突。一旦这个文件冲突了项目就打不开了，然后就非常不情愿地用文本编辑器打开这个文件，人肉搜索 &amp;gt;&amp;gt;&amp;gt; &amp;lt;&amp;lt;&amp;lt; 或者 === 来进行人肉替换解决冲突问题。 这简直就是浪费青春，如果合并的是一个距离上次 c">
<meta name="keywords" content="Git,Xcode,iOS">
<meta property="og:type" content="article">
<meta property="og:title" content="解决iOS项目文件合并.xcodeproj冲突">
<meta property="og:url" content="https://bingozb.github.io/11.html">
<meta property="og:site_name" content="Bingo's Blog">
<meta property="og:description" content="前言用 Xcode 做 iOS 开发的同学都知道，在项目根目录里有一个  project.xcodeproj 文件。如果多人协作，项目合并的时候这个文件非常容易有冲突。一旦这个文件冲突了项目就打不开了，然后就非常不情愿地用文本编辑器打开这个文件，人肉搜索 &amp;gt;&amp;gt;&amp;gt; &amp;lt;&amp;lt;&amp;lt; 或者 === 来进行人肉替换解决冲突问题。 这简直就是浪费青春，如果合并的是一个距离上次 c">
<meta property="og:updated_time" content="2017-09-04T19:06:15.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="解决iOS项目文件合并.xcodeproj冲突">
<meta name="twitter:description" content="前言用 Xcode 做 iOS 开发的同学都知道，在项目根目录里有一个  project.xcodeproj 文件。如果多人协作，项目合并的时候这个文件非常容易有冲突。一旦这个文件冲突了项目就打不开了，然后就非常不情愿地用文本编辑器打开这个文件，人肉搜索 &amp;gt;&amp;gt;&amp;gt; &amp;lt;&amp;lt;&amp;lt; 或者 === 来进行人肉替换解决冲突问题。 这简直就是浪费青春，如果合并的是一个距离上次 c">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 'undefined',
      author: '博主'
    },
    algolia: {
      applicationID: 'JE30EVH7NI',
      apiKey: '862bb3deb9a3166ed99de0be6527f59c',
      indexName: 'blog',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":"找不到关于「 ${query} 」的文章","hits_stats":"共找到 ${hits} 篇文章，花了 ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://bingozb.github.io/11.html"/>





  <title>解决iOS项目文件合并.xcodeproj冲突 | Bingo's Blog</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?c8a59b9753bce3ec58f81c89e2acce96";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Bingo's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Stay Hungry, Stay Foolish.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocapitalize="off" autocomplete="off" autocorrect="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://bingozb.github.io/11.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Bingo">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Bingo's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                解决iOS项目文件合并.xcodeproj冲突
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-09T01:00:42+08:00">
                2017-02-09
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/解决方案/" itemprop="url" rel="index">
                    <span itemprop="name">解决方案</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/11.html#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="11.html" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          
             <span id="/11.html" class="leancloud_visitors" data-flag-title="解决iOS项目文件合并.xcodeproj冲突">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>用 Xcode 做 iOS 开发的同学都知道，在项目根目录里有一个  project.xcodeproj 文件。如果多人协作，项目合并的时候这个文件非常容易有冲突。一旦这个文件冲突了项目就打不开了，然后就非常不情愿地用文本编辑器打开这个文件，人肉搜索 &gt;&gt;&gt; &lt;&lt;&lt; 或者 === 来进行人肉替换解决冲突问题。</p>
<p>这简直就是浪费青春，如果合并的是一个距离上次 commit 已经很了久的崭新的 commit，你估计会找同事“聊聊人生”… 怎么解决这个问题呢？</p>
<a id="more"></a>
<h2 id="xcodeproj"><a href="#xcodeproj" class="headerlink" title=".xcodeproj"></a>.xcodeproj</h2><p>项目 .xcodeproj 文件夹底下一般有4个文件:</p>
<ul>
<li>project.pbxproj 文件</li>
<li>xcuserdata 文件夹</li>
<li>xcshareddata 文件夹</li>
<li>project.xcworkspace 文件夹</li>
</ul>
<h3 id="xcuserdata-xcshareddata"><a href="#xcuserdata-xcshareddata" class="headerlink" title="xcuserdata / xcshareddata"></a>xcuserdata / xcshareddata</h3><p>存放用户相关的文件，包含 user state，folders 的状态，最后打开的文件等。一般来说是不需要提交的也不会冲突的。</p>
<h3 id="project-xcworkspace"><a href="#project-xcworkspace" class="headerlink" title="project.xcworkspace"></a>project.xcworkspace</h3><p>workspace 是一种 Xcode documentation，可以将多个 project 和其它文件放到一起，这样可以 work on them together。一个 project 也可以属于多个 workspace。所以简单来讲，workspace 里面就是一个或多个 projects 的 reference，放在一起，有时候比较好工作。也包含一些用户的断点设置信息。</p>
<p>如果项目里面根本就没有 workspace 的概念，或者只有一个 workspace + 一个 project 时，这个 workspace 并不会有什么变动，那么这个文件夹可以忽略，更不会出现冲突问题。如果 project 很依赖 workspace，没有 workspace 就运行不了，虽然不能忽略这个文件夹，但也不容易出现冲突。出现冲突最多的是下面的 project.pbxproj 文件。</p>
<h3 id="project-pbxproj"><a href="#project-pbxproj" class="headerlink" title="project.pbxproj"></a>project.pbxproj</h3><p>而 project.pbxproj 这个文件被称之为“梦魇”，是一个老式的 plist，记录整个项目的层次结构，包含了所有此项目 build 需要的元数据，setting、file reference、configuration、targets 等等。也就是说，这个文件代表的就是这个 project。</p>
<figure class="highlight lsl"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/* Begin PBXBuildFile section */</span></div><div class="line">	<span class="number">351</span>B785F1E2B34E100ED9945 <span class="comment">/* DKOrderDetailViewController.m in Sources */</span> = &#123;isa = PBXBuildFile; fileRef = <span class="number">351</span>B785D1E2B34E100ED9945 <span class="comment">/* DKOrderDetailViewController.m */</span>; &#125;;</div><div class="line">	<span class="number">351</span>B78601E2B34E100ED9945 <span class="comment">/* DKOrderDetailViewController.xib in Resources */</span> = &#123;isa = PBXBuildFile; fileRef = <span class="number">351</span>B785E1E2B34E100ED9945 <span class="comment">/* DKOrderDetailViewController.xib */</span>; &#125;;</div><div class="line">	<span class="number">3543</span>B7751E2C765600F8F65C <span class="comment">/* DKOrderSuccessViewController.m in Sources */</span> = &#123;isa = PBXBuildFile; fileRef = <span class="number">3543</span>B7731E2C765600F8F65C <span class="comment">/* DKOrderSuccessViewController.m */</span>; &#125;;</div></pre></td></tr></table></figure>
<p>项目越大，文件越多，这里记录的信息就越多。我们现在的这个文件已经有三千多行了，我只选取了前面三行。 可以看到每一行的开头大概都是一个24位的16进制数字，然后就是一个文件名 ，在最后有一个 isa 和一个 fileRef（文件引用）。当然这里面的数据还包括很多东西，比如 Target、Group、FileRef 等就不再一一列举出来了。</p>
<h2 id="为什么会冲突"><a href="#为什么会冲突" class="headerlink" title="为什么会冲突"></a>为什么会冲突</h2><p>上面简单说了冲突的罪魁祸首是 project.pbxproj，并简单说了每行的内容。很明显每一个文件都会有一个文件引用 （fileRef）。当多人协作的时候，在同一份项目中，不同开发者同时创建不同的文件，会出现创建出来的引用 fileRef 是相同的，但却指向了不同的文件。比如开发者A 创建了一个 ViewController，可能会产生这样一条记录 A：</p>
<figure class="highlight nix"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">D7921FD21E4B9ED1001C43E9 <span class="comment">/* DKViewController.m in Sources */</span> = &#123;<span class="attr">isa</span> = PBXBuildFile; <span class="attr">fileRef</span> = D7921FD11E4B9ED1001C43E9 <span class="comment">/* DKViewController.m */</span>; &#125;;</div></pre></td></tr></table></figure>
<p>而 开发者B 创建了一个 xib文件，可能会产生这样一条记录 B：</p>
<figure class="highlight nix"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">D7921FD41E4B9F3F001C43E9 <span class="comment">/* View.xib in Resources */</span> = &#123;<span class="attr">isa</span> = PBXBuildFile; <span class="attr">fileRef</span> = D7921FD31E4B9F3F001C43E9 <span class="comment">/* View.xib */</span>; &#125;;</div></pre></td></tr></table></figure>
<p>观察两条记录，就可以发现，相同的文件引用，指向了不同的文件。两个用户修改了同一个文件的同一块区域，git 会报内容冲突。坑爹的问题出现了，这是两个不同的文件，但是引用是同一个，无法像前言说的直接手动&gt;&gt;&gt;找到冲突的位置，然后把两个都保留下来。因为一个引用不可能引用两个不同文件。这个冲突怎么办？只能先删掉一条引用记录，解决冲突后，再手动把被删掉引用的文件重新拉进项目。</p>
<h2 id="优雅地解决"><a href="#优雅地解决" class="headerlink" title="优雅地解决"></a>优雅地解决</h2><p>有没有办法解决这个冲突问题？答案是肯定的。在知乎上面搜了一圈，普遍有两种做法。一个是约定型的，另一个是解决型的。</p>
<h3 id="约定型"><a href="#约定型" class="headerlink" title="约定型"></a>约定型</h3><p><em>需要增加文件时先增加完空文件后立刻 checkin 一次，让别人每次改动 pbxproj 的时候改动之前 checkout 一次，保证有交叉时间是可能性最小</em></p>
<p>就是你先创建一个空文件，生成了一个引用后，就push一遍代码。然后让别人pull，让他在创建新文件之前就已经有了你创建的空文件和生成的引用，这样相当于在你之后创建新文件，而不是同时创建了。</p>
<h3 id="解决型"><a href="#解决型" class="headerlink" title="解决型"></a>解决型</h3><p><em>xUnique</em></p>
<p>开源 <a href="https://github.com/truebit/xUnique" target="_blank" rel="external">GitHub 地址</a></p>
<p><a href="https://pypi.python.org/packages/64/e0/bd7e2ce2c78145578eea4c3e8d8cf2cd735545fb03207544e0a44e3410d4/xUnique-4.1.4.tar.gz" target="_blank" rel="external">xUnique 下载地址</a></p>
<p>What it does &amp; How it works:</p>
<ol>
<li>convert <code>project.pbxproj</code> to JSON format</li>
<li>Iterate all <code>objects</code> in JSON and give every UUID an absolute path, and create a new UUID using MD5 hex digest of the path<ul>
<li>All elements in this json object is actually connected as a tree</li>
<li>We give a path attribute to every node of the tree using its unique attribute; this path is the absolute path to the root node,</li>
<li>Apply MD5 hex digest to the path for the node</li>
</ul>
</li>
<li>Replace all old UUIDs with the MD5 hex digest and also remove unused UUIDs that are not in the current node tree and UUIDs in wrong format</li>
<li>Sort the project file inlcuding <code>children</code>, <code>files</code>, <code>PBXFileReference</code> and <code>PBXBuildFile</code> list and remove all duplicated entries in these lists<ul>
<li>see <code>sort_pbxproj</code> method in xUnique.py if you want to know the implementation;</li>
<li>It’s ported from my modified <a href="https://github.com/truebit/webkit/commits/master/Tools/Scripts/sort-Xcode-project-file" target="_blank" rel="external">sort-Xcode-project-file</a>, with some differences in ordering <code>PBXFileReference</code> and <code>PBXBuildFile</code></li>
</ul>
</li>
</ol>
<p>大概的意思是：</p>
<ul>
<li>替换所有 UUID 为项目内永久不变的 MD5 digest</li>
<li>删除所有多余的节点（一般是合并的时候疏忽导致的）</li>
<li>用 Python 重写了修改过的的 sort-Xcode-project-file 的排序功能，修改版相较原版增加了以下功能：<ul>
<li>对 PBXFileReference 和 PBXBuildFile 区块的排序</li>
<li>使用脚本后如果内容没有变化不会生成新文件，避免一次不必要的 commit</li>
</ul>
</li>
</ul>
<h4 id="安装方法"><a href="#安装方法" class="headerlink" title="安装方法"></a>安装方法</h4><ul>
<li>下载 xUnique，解压后， python 安装命令行脚本 setup.py</li>
</ul>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ python setup<span class="selector-class">.py</span> install</div></pre></td></tr></table></figure>
<ul>
<li>验证是否安装成功</li>
</ul>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$ </span>xunique -h</div></pre></td></tr></table></figure>
<h4 id="使用方法"><a href="#使用方法" class="headerlink" title="使用方法"></a>使用方法</h4><p>使用方法有两种，一种是 Git hook，另一种是 Xcode “build post-action”。这里只用推荐的 Git hook 的方式。</p>
<ul>
<li>创建 pre-commit 的钩子</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ &#123; <span class="built_in">echo</span> <span class="string">'#!/bin/sh'</span>; <span class="built_in">echo</span> <span class="string">'xunique path/to/MyProject.xcodeproj'</span>; &#125; &gt; .git/hooks/pre-commit</div></pre></td></tr></table></figure>
<p>如果有使用 CocoaPods，还需要把 Pods.xcodeproj 也加上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ &#123; <span class="built_in">echo</span> <span class="string">'#!/bin/sh'</span>; <span class="built_in">echo</span> <span class="string">'xunique path/to/MyProject.xcodeproj'</span>; <span class="built_in">echo</span> <span class="string">'xunique path/to/Pods.xcodeproj'</span>; &#125; &gt; .git/hooks/pre-commit</div></pre></td></tr></table></figure>
<ul>
<li>给钩子加权限</li>
</ul>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ chmod <span class="number">755</span> .git<span class="regexp">/hooks/</span>pre-commit</div></pre></td></tr></table></figure>
<ul>
<li>commit</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">$ git <span class="keyword">commit</span> -a -m <span class="string">"test xUnique"</span></div><div class="line">Uniquify <span class="keyword">and</span> <span class="keyword">Sort</span></div><div class="line">Uniquify done</div><div class="line"><span class="keyword">Sort</span> done</div><div class="line"><span class="keyword">Following</span> <span class="keyword">lines</span> were deleted because <span class="keyword">of</span> duplication:</div><div class="line">				<span class="number">043592</span>DF7047127330AF6F032495AC6C <span class="comment">/* iflyMSC.framework */</span>,</div><div class="line"> 				<span class="number">043592</span>DF7047127330AF6F032495AC6C <span class="comment">/* iflyMSC.framework */</span>,</div><div class="line">Uniquify <span class="keyword">and</span> <span class="keyword">Sort</span> done</div><div class="line"><span class="keyword">File</span> <span class="string">'project.pbxproj'</span> was modified, please <span class="keyword">add</span> it <span class="keyword">and</span> <span class="keyword">commit</span> again <span class="keyword">to</span> submit xUnique result.</div><div class="line"><span class="keyword">NOTICE</span>: <span class="keyword">If</span> you want <span class="keyword">to</span> submit xUnique <span class="keyword">result</span> combined <span class="keyword">with</span> original <span class="keyword">commit</span>, <span class="keyword">use</span> <span class="keyword">option</span> <span class="string">'-c'</span> <span class="keyword">in</span> command.</div><div class="line">Uniquify <span class="keyword">and</span> <span class="keyword">Sort</span></div><div class="line">Uniquify done</div><div class="line"><span class="keyword">Sort</span> done</div><div class="line">Uniquify <span class="keyword">and</span> <span class="keyword">Sort</span> done</div><div class="line"><span class="keyword">File</span> <span class="string">'project.pbxproj'</span> was modified, please <span class="keyword">add</span> it <span class="keyword">and</span> <span class="keyword">commit</span> again <span class="keyword">to</span> submit xUnique result.</div><div class="line"><span class="keyword">NOTICE</span>: <span class="keyword">If</span> you want <span class="keyword">to</span> submit xUnique <span class="keyword">result</span> combined <span class="keyword">with</span> original <span class="keyword">commit</span>, <span class="keyword">use</span> <span class="keyword">option</span> <span class="string">'-c'</span> <span class="keyword">in</span> command.</div><div class="line">[<span class="keyword">master</span> d9569e5] <span class="keyword">test</span> xUnique</div><div class="line"> <span class="number">1</span> <span class="keyword">file</span> <span class="keyword">changed</span>, <span class="number">566</span> insertions(+)</div><div class="line"> <span class="keyword">create</span> <span class="keyword">mode</span> <span class="number">100755</span> xUnique.py</div></pre></td></tr></table></figure>
<p>根据提示，两个 ‘project.pbxproj’ 文件被修改了，需要 add，然后再次 commit。</p>
<p>看一下状态，果然被修改了。</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ git status -s</div><div class="line"> M Pods/Pods.xcodeproj/<span class="keyword">project</span>.pbxproj</div><div class="line"> M SF.xcodeproj/<span class="keyword">project</span>.pbxproj</div></pre></td></tr></table></figure>
<ul>
<li>再次 commit</li>
</ul>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">add</span> .</div><div class="line">$ git status -s</div><div class="line">M  Pods/Pods.xcodeproj/project.pbxproj</div><div class="line">M  SF.xcodeproj/project.pbxproj</div><div class="line">$ git commit -<span class="keyword">a</span> -<span class="keyword">m</span> <span class="string">"test xUnique"</span></div><div class="line"></div><div class="line">Ignore uniquify, <span class="keyword">no</span> <span class="keyword">changes</span> made <span class="keyword">to</span> <span class="comment">"/Users/bingo/Desktop/iOS/iOS Project/SF/SF.xcodeproj/project.pbxproj</span></div><div class="line">Ignore <span class="keyword">sort</span>, <span class="keyword">no</span> <span class="keyword">changes</span> made <span class="keyword">to</span> <span class="comment">"/Users/bingo/Desktop/iOS/iOS Project/SF/SF.xcodeproj/project.pbxproj</span></div><div class="line">Uniquify <span class="built_in">and</span> Sort done</div><div class="line">Uniquify <span class="built_in">and</span> Sort</div><div class="line">Ignore uniquify, <span class="keyword">no</span> <span class="keyword">changes</span> made <span class="keyword">to</span> <span class="comment">"/Users/bingo/Desktop/iOS/iOS Project/SF/Pods/Pods.xcodeproj/project.pbxproj</span></div><div class="line">Ignore <span class="keyword">sort</span>, <span class="keyword">no</span> <span class="keyword">changes</span> made <span class="keyword">to</span> <span class="comment">"/Users/bingo/Desktop/iOS/iOS Project/SF/Pods/Pods.xcodeproj/project.pbxproj</span></div><div class="line">Uniquify <span class="built_in">and</span> Sort done</div><div class="line">[master <span class="number">861</span>b932] test xUnique</div><div class="line"> <span class="number">2</span> <span class="keyword">files</span> changed, <span class="number">6251</span> insertions(+), <span class="number">6253</span> deletions(-)</div><div class="line"> rewrite SF.xcodeproj/project.pbxproj (<span class="number">79</span>%)</div></pre></td></tr></table></figure>
<p>根据提示，这个时候已经忽略排序了，因为之前已经排过一次序了，顺序没有改变。再看一下当前的 status，已经没有修改那两个文件了。</p>
<ul>
<li>合并 commit</li>
</ul>
<p>如果有改动了任意一个 project.pbxproj 文件，就需要 commit 两次。最好合并一下 commit，参考<a href="https://bingo.ren/2017/01/29/8/" target="_blank" rel="external">《Git 合并Commit》</a>，比如用 rebase 来合并。</p>
<h4 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h4><p>如果用 Git 客户端如 GitHub Desktop 进行 commit 操作的时候，可能会报错找不到 xunique 命令，这时可以到 pre-commit 这个钩子中将 xunique 补全为绝对路径。</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta-keyword">/usr/</span>local<span class="meta-keyword">/bin/</span>xunique <span class="meta-keyword">/path/</span>to/project.xcodeproj</div><div class="line"><span class="meta-keyword">/usr/</span>local<span class="meta-keyword">/bin/</span>xunique <span class="meta-keyword">/path/</span>to/Pods.xcodeproj</div></pre></td></tr></table></figure>
<p>然后就可以直接在客户端跟往常一样进行 commit 操作了。在终端命令行操作则不会出现这个问题。</p>
<h2 id="后话"><a href="#后话" class="headerlink" title="后话"></a>后话</h2><p>以后 project.pbxproj 的冲突问题就解决了。但要注意，多人协作的时候，如果团队中的其中一个人使用了 xUnique，所有人就都要用 xUnique，否则 project.pbxproj 就会全乱掉。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <ul class="post-copyright">
    <li class="post-copyright-author">
      <strong>本文作者：</strong>
      Bingo
    </li>
    <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://bingozb.github.io/11.html" title="解决iOS项目文件合并.xcodeproj冲突">https://bingozb.github.io/11.html</a>
    </li>
    <li class="post-copyright-license">
      <strong>版权声明： </strong>
      本博客所有文章除特别声明外，均采用 MIT 许可协议。转载请注明出处！
    </li>
  </ul>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Git/" rel="tag"># Git</a>
          
            <a href="/tags/Xcode/" rel="tag"># Xcode</a>
          
            <a href="/tags/iOS/" rel="tag"># iOS</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/12.html" rel="next" title="彻底删除MySQL相关文件">
                <i class="fa fa-chevron-left"></i> 彻底删除MySQL相关文件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/10.html" rel="prev" title="解决讨厌的.DS_Store文件（下）">
                解决讨厌的.DS_Store文件（下） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="SOHUCS"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.jpg"
               alt="Bingo" />
          <p class="site-author-name" itemprop="name">Bingo</p>
           
              <p class="site-description motion-element" itemprop="description">He who hesitates is lost.</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">55</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">22</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/bingozb" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://coding.net/u/bingozb" target="_blank" title="Coding">
                  
                    <i class="fa fa-fw fa-git"></i>
                  
                  Coding
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/bingo_v587" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100013406670597" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#xcodeproj"><span class="nav-number">2.</span> <span class="nav-text">.xcodeproj</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#xcuserdata-xcshareddata"><span class="nav-number">2.1.</span> <span class="nav-text">xcuserdata / xcshareddata</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#project-xcworkspace"><span class="nav-number">2.2.</span> <span class="nav-text">project.xcworkspace</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#project-pbxproj"><span class="nav-number">2.3.</span> <span class="nav-text">project.pbxproj</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么会冲突"><span class="nav-number">3.</span> <span class="nav-text">为什么会冲突</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#优雅地解决"><span class="nav-number">4.</span> <span class="nav-text">优雅地解决</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#约定型"><span class="nav-number">4.1.</span> <span class="nav-text">约定型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解决型"><span class="nav-number">4.2.</span> <span class="nav-text">解决型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装方法"><span class="nav-number">4.2.1.</span> <span class="nav-text">安装方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用方法"><span class="nav-number">4.2.2.</span> <span class="nav-text">使用方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#补充"><span class="nav-number">4.2.3.</span> <span class="nav-text">补充</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#后话"><span class="nav-number">5.</span> <span class="nav-text">后话</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  Copyright © 
  <span itemprop="copyrightYear">2017
  </span>
  <span class="author" itemprop="copyrightHolder">Bingo
  </span>
  All rights reserved.
</div>
        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cytcdzpa3';
      var conf = 'c0c6117021d1cea9f11629100efd8446';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (search_path.endsWith("json")) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      $('#local-search-input').focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('-1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("A9MeTkIR49W9kOOSvkggsXge-gzGzoHsz", "HaIEOSDyxpcjwOjRjCYxiWjA");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

</body>
</html>
